package system;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RowSorter;
import javax.swing.SwingUtilities;

import connect.connect;
import javax.swing.table.DefaultTableModel;



public class Table  {
	

	private static JScrollPane scroll;
	
	public static  void DrawTable(String pi_id,JPanel panel,JTable table) {

	panel.remove(panel.getComponent(panel.getComponentCount()-1));
	Vector chead = new Vector();// chead==columnHeads ��ͷ
	Vector rows = new Vector();// ��
	
	DefaultTableModel model = null;
	
	ResultSet rs;
	ResultSetMetaData rsmd = null;
	try {
		Connection conn = connect.getConnection();
		Statement stat = conn.createStatement();

		rs = stat
				.executeQuery("select gd_id as '物品编号',gd_name as '物品名称',gd_type as '物品类型',gd_unit as '计量单位',amount as '数量',unitprice as '单价',tax as '税率',taxprice as '含税单价',total as '合计' from PutInStorageDetail where PutInStorageDetail.pi_id='"
						+ pi_id + "' ");
		rsmd = rs.getMetaData();

		for (int i = 1; i <= rsmd.getColumnCount(); ++i) {
			chead.addElement(rsmd.getColumnName(i));
		}

		while (rs.next()) { // ����ȡ�����
			Vector crow = new Vector(); // crow== current row
			for (int i = 1; i <= rsmd.getColumnCount(); ++i) { // ��ȡ��ݿ��е���Ԫ�طŵ�crow������
				crow.addElement(rs.getString(i));
			}// �ѵ�ǰ�е�����crow�ŵ�rows��
			rows.addElement(crow);
		}
		// stat.close();
		// conn.close();
	} catch (SQLException sqlex) {
		sqlex.printStackTrace();
	} catch (IOException e11) {
		e11.printStackTrace();
	}

	// ��������������


//	table=new JTable();

	
	model = new DefaultTableModel(rows,chead);
	 table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
	 table.setModel(model);
	 scroll = new JScrollPane(table);
	
	scroll.setBounds(132, 423, 715, 118);
	panel.add(scroll);
	scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

	
	}

 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
